package cn.com.zero.front.auth.controller;

import cn.com.zero.api.auth.vo.OnlineUserVO;
import cn.com.zero.db.vo.PageParamsVO;
import cn.com.zero.db.vo.PageVO;
import cn.com.zero.front.auth.constant.FrontAuthConstants;
import cn.com.zero.front.auth.service.impl.FrontOnlineUserService;
import cn.com.zero.web.controller.BaseController;
import cn.com.zero.web.util.PageRequestUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;

/**
 * @author xiongxj
 * @version 1.0.0
 * @Description 用户端在线用户controller
 * @createTime 2023/3/30 10:54
 */
@RestController
@Api(tags = "用户端在线用户接口")
@RequestMapping("/front/onlineUser")
public class FrontOnlineUserController extends BaseController {
    private FrontOnlineUserService frontOnlineUserService;

    @GetMapping("/list")
    public PageVO<OnlineUserVO> list(String[] searchUserIds, String loginDevice, String loginIp,
                                     Date loginBeginTime, Date loginEndTime) {
        PageParamsVO pageParamsVO = PageRequestUtil.getPageParams();
        return frontOnlineUserService.getOnlineUsers(FrontAuthConstants.FRONT_SIDE_NAME, pageParamsVO,
                null == searchUserIds ? null :Arrays.asList(searchUserIds), loginDevice, loginIp, loginBeginTime, loginEndTime);
    }

    @PostMapping("/kickoff")
    public void kickoff(String userId, String loginDevice) {
        frontOnlineUserService.kickOffUser(FrontAuthConstants.FRONT_SIDE_NAME, userId, loginDevice);
    }

    @Autowired
    public void setFrontOnlineUserService(FrontOnlineUserService frontOnlineUserService) {
        this.frontOnlineUserService = frontOnlineUserService;
    }
}
